package com.loongtech.bi.action.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import javax.faces.context.FacesContext;
import javax.faces.context.ExternalContext;

import com.loongtech.bi.manager.realTime.ServerOnlineNumManager;

/**
 * 获取服务器在线时间json
 */
@Controller("serverOnlineAction")
@Scope("view")
public class GetServerOnline {
	@Autowired
	private ServerOnlineNumManager manager;
	
	private static final int ServerTimeZone = 9;
	private int timeZone = 9; // 时区

	@Autowired
	public void init() {
		timeZone = 9;
	}

	public void search() {
		String retMsg = manager.getServerOnlineNum(ServerTimeZone - timeZone);
		if( null == retMsg || retMsg.isEmpty()) {
			return;
		}

		try{
			FacesContext facesContext = FacesContext.getCurrentInstance();
			ExternalContext externalContext = facesContext.getExternalContext();
			externalContext.setResponseContentType("application/json");
			externalContext.setResponseCharacterEncoding("UTF-8");
			externalContext.getResponseOutputWriter().write(retMsg);
			facesContext.responseComplete();
		}catch (Exception ex){
			ex.printStackTrace();
		}
	}

	public int getTimeZone() {
		return timeZone;
	}

	public void setTimeZone(int timeZone) {
		this.timeZone = timeZone;
	}
}
